﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunitySystem.PublicOfficialSelectionService;

namespace CommunitySystem
{
    public partial class KaoGuanDetailWindow : ChildWindow
    {
        private PublicOfficialSelectionServiceClient Client = new PublicOfficialSelectionServiceClient();
        private KaoGuanModel model = new KaoGuanModel();
        private KaoGuanDetailModel model1 = new KaoGuanDetailModel();
        public int ID;
        public KaoGuanDetailWindow(int iD)
        {
            InitializeComponent();
            ID = iD;
            //for (int i = DateTime.Today.Year; i > DateTime.Today.Year - 10; i--)
            //{
            //    ComboBoxItem cbi = new ComboBoxItem();
            //    cbi.Content = i.ToString();
            //    cbi.Tag = i;
            //    nian.Items.Add(cbi);
            //}
            this.Title = "编辑考官详细信息";
            Client.GetKaoGuanDetailModelCompleted += new EventHandler<GetKaoGuanDetailModelCompletedEventArgs>(Client_GetKaoGuanDetailModelCompleted);
            Client.GetKaoGuanDetailModelAsync("", 0, ID, "选调交流");
        }

        void Client_GetKaoGuanDetailModelCompleted(object sender, GetKaoGuanDetailModelCompletedEventArgs e)
        {
            if (e.Result != null)
                model = e.Result[0];
            this.DataContext = model;
            //nian.SelectedIndex = DateTime.Today.Year - model.Year;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            model1.ID = ID;
            model1.Year = model.Year;
            model1.KaoGuanID = model.KaoGuanID;
            model1.KGType = model.KGType;
            model1.XBType = model.XBType;
           
            Client.UpdateKaoGuanDetailModelCompleted += new EventHandler<UpdateKaoGuanDetailModelCompletedEventArgs>(Client_UpdateKaoGuanDetailModelCompleted);
            Client.UpdateKaoGuanDetailModelAsync(model1);

        }

        void Client_UpdateKaoGuanDetailModelCompleted(object sender, UpdateKaoGuanDetailModelCompletedEventArgs e)
        {
            if (e.Result == true)
            {
                SilverlightMessageBoxLibrary.Message.InfoMessage("编辑成功！");
                this.DialogResult = true;
            }
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}
